Personify Data Services allows you to upload files through the “FileUpload” Service Operation. The “SvcClient” code is modified to provide a helper method to invoke the service operation. For more information on the SvcClient code, please see #11 Executing Service Operations (using .NET client).
The following configuration files have to be modified in order to support the File Upload and File Download feature:
The following needs to be available under <system.web> for 4MB upload (default max.):
<httpRuntime maxRequestLength="4194304"/>
The following needs to be available under <configuration> (usually at the bottom):
The "name" attribute of the "service" element (highlighted below in yellow) must be set to a fully qualified name of the service entry point class (e.g., PersonifyDataServices.ABA.PersonifyDataABA).
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="PersonifyDataServices.PersonifyData">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="higherMessageSize" contract="System.Data.Services.IRequestHandler" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="higherMessageSize" maxBufferSize="4194304" maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304" transferMode="Streamed">
<readerQuotas maxDepth="32" maxStringContentLength="4194304" maxArrayLength="4194304" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
If you are using the File Upload or File Download feature, the following items highlighted in blue need to be added and configured under the section <Section Name="DataServices">:
<Item Name="FileUploadSharedPath" Value="[FileUploadSharedPathValue]"/>
<Item Name="FileSystemCleanupEnabled" Value="[FileSystemCleanupEnabledValue]" />
<Item Name="TimeOfDayToCleanUpAttachments"Value="[TimeOfDayToCleanUpAttachmentsValue]"/>
<Item Name="AgeofFileToDeleteInDays" Value="[AgeofFileToDeleteInDaysValue]"/>
Where
[FileUploadSharedPathValue]:
is the shared server path which host your upload files.
[FileSystemCleanupEnabledValue]: True/False to
specify whether you want to enable system to clean up old uploaded files.
[TimeOfDayToCleanUpAttachmentsValue]: time when
the uploaded files are cleaned up. This must specify in military format.
IE: 19:00 is 7:00 PM 1:00 is 1:00 AM 0:15 is 12:15 AM 0:00 is midnight
12:00 is noon.
[AgeofFileToDeleteInDaysValue]: the number of
days the files uploaded to be used to determined which files are cleaned
up.
The web server automatically cleans up documents and files that are placed in a staging location during the file upload/file download process. This operation is performed as a background process, reads the configured values from the config.xml file, and then executes its cleanup implementation at the scheduled time.
For example, you may have “CustomerRelatedDocument” as an entity with “RelatedDocumentPath” as a property, with the “IsAttachment” attribute set to “True”. The “FileAttachmentPropertyMapping.xml” (usually generated through the Personify WSD and deployed to “bin” folder of PDS) would have the following:
<?xml version="1.0" encoding="utf-8" ?>
<PropertyMappings>
<PropertyMapping ApiCollection=" CustomerInfo.CustomerRelatedDocuments" PropertyForFilePath="RelatedDocumentPath" />
</PropertyMappings>
The following is the code which uploads the file through the entity created above (uses the latest SvcClient code):
public void
FileUploadTest()
{
try
{
//Upload the document first
string fileLoc =
SvcClient.FileUpload(System.IO.File.ReadAllBytes("c:\\1.jpg"), "1.jpg");
Assert.IsFalse(string.IsNullOrEmpty(fileLoc));
//Create a new CustomerRelatedDocument instance (from server to get default values)
CustomerRelatedDocument oRespCreate = SvcClient.Create<CustomerRelatedDocument>();
Assert.IsTrue(oRespCreate.CustomerRelatedDocumentId > 0);
Assert.IsNotNull(oRespCreate.EntityGUID);
//Provide values and Save
oRespCreate.MasterCustomerId = "JEFFERSON";
oRespCreate.SubCustomerId = 0;
oRespCreate.RelatedDocumentCodeString = "RESUME";
oRespCreate.RelatedDocumentDate = DateTime.Now;
oRespCreate.RelatedDocumentPath = fileLoc;
oRespCreate.RelatedDocumentDescription = "1.jpg"; //this has to be the target file name for this entity
oRespCreate.IsFileUploadRequired = true; //necessary for this entity
CustomerRelatedDocument oRespSave = SvcClient.Save<CustomerRelatedDocument>(oRespCreate);
Assert.IsTrue(oRespSave.CustomerRelatedDocumentId > 0);
Assert.IsNotNull(oRespSave.EntityGUID);
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
Once a file gets uploaded using the above code, it should be viewable from Personify back office automatically.